package demo2;

public class Person implements Comparable<Person> {
    public String name;
    public int age;
    public double score;

    public Person(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Person o) {
//        return this.age-o.age;
        return o.age-this.age;//交换顺序就可以将年龄按照从大到小的顺序排
    }
}
